package com;

import com.mapper.Employee;
import com.test.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeByIdTest() {
SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee=sqlSession.selectOne("selectByPrimaryKey", 3L);
        System.out.println(employee.toString());
        sqlSession.commit();//提交事务
        sqlSession.close();//
        System.out.println();
    }
    @Test
    public void addEmployeeTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee=new Employee();
        employee.setId(4);
        employee.setName("赵六");
        employee.setAge(16);
        employee.getposition("临时工");
        int addInt=sqlSession.insert("insert", employee);
        System.out.println(addInt);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
        System.out.println(addInt);
    }
    @Test
    public void updateEmployeeTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee=new Employee();
        employee.setId(2);
        employee.setName("赵六");
        employee.setAge(16);
        employee.getposition("临时工");
        int addInt=sqlSession.insert("insert", employee);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
        System.out.println();

    }
    @Test
    public void  deleteEmployeeById() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        int d=sqlSession.delete("deleteByPrimaryKey", 1L);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
        System.out.println(d);
    }
}
